package com.tpc.control.jpa;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Status entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "status", catalog = "production_control")
public class Status implements java.io.Serializable {

	// Fields

	private StatusId id;
	private StatusType statusType;
	private String statusName;
	private Set<StatusMapping> statusMappings = new HashSet<StatusMapping>(0);

	// Constructors

	/** default constructor */
	public Status() {
	}

	/** minimal constructor */
	public Status(StatusId id, StatusType statusType, String statusName) {
		this.id = id;
		this.statusType = statusType;
		this.statusName = statusName;
	}

	/** full constructor */
	public Status(StatusId id, StatusType statusType, String statusName,
			Set<StatusMapping> statusMappings) {
		this.id = id;
		this.statusType = statusType;
		this.statusName = statusName;
		this.statusMappings = statusMappings;
	}

	// Property accessors
	@EmbeddedId
	@AttributeOverrides( {
			@AttributeOverride(name = "statusType", column = @Column(name = "status_type", nullable = false, length = 20)),
			@AttributeOverride(name = "statusCode", column = @Column(name = "status_code", nullable = false)) })
	public StatusId getId() {
		return this.id;
	}

	public void setId(StatusId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "status_type", nullable = false, insertable = false, updatable = false)
	public StatusType getStatusType() {
		return this.statusType;
	}

	public void setStatusType(StatusType statusType) {
		this.statusType = statusType;
	}

	@Column(name = "status_name", nullable = false, length = 100)
	public String getStatusName() {
		return this.statusName;
	}

	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "status")
	public Set<StatusMapping> getStatusMappings() {
		return this.statusMappings;
	}

	public void setStatusMappings(Set<StatusMapping> statusMappings) {
		this.statusMappings = statusMappings;
	}
	
	/* Customize */
	public List<String> retrieveStatusMappingString() {
		List<String> data = new ArrayList();
		Iterator iter = getStatusMappings().iterator();
		while (iter.hasNext()) {
			StatusMapping statusMapping = (StatusMapping)iter.next();
			data.add(statusMapping.getId().getStatusSap());
		}
		return data;
	}

}